package com.bqtv.sport.ui.home

import android.content.Context
import android.content.Intent
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.gyf.immersionbar.ImmersionBar
import com.bqtv.sport.R
import com.bqtv.sport.adapter.HomeHotAdapter
import com.bqtv.sport.adapter.SearchHotAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.commen.utils.DpUtil
import com.bqtv.sport.commen.widget.GridItemDecoration
import com.bqtv.sport.databinding.ActivitySearchBinding
import com.library.flowlayout.FlowLayoutManager
import com.library.flowlayout.SpaceItemDecoration

class SearchActivity : AppActivity<ActivitySearchBinding>() {
    private lateinit var hotAdapter: SearchHotAdapter
    private lateinit var detailAdapter: HomeHotAdapter
    companion object {
        fun start(context: Context) {
            val intent = Intent(context, SearchActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding() = ActivitySearchBinding.inflate(layoutInflater)

    override fun initView() {
        ImmersionBar.setTitleBarMarginTop(this, binding.llTitle)
        binding.rcvHot.layoutManager= FlowLayoutManager()
        binding.rcvHot.addItemDecoration(SpaceItemDecoration(DpUtil.dp2px(10)))
        hotAdapter= SearchHotAdapter()
        binding.rcvHot.adapter=hotAdapter

        binding.rcvDetail.layoutManager =
            StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        binding.rcvDetail.addItemDecoration(
            GridItemDecoration(
                getContext(), 2,
                GridItemDecoration.LineDrawMode.HORIZONTAL, 10, 15
            )
        )

        detailAdapter = HomeHotAdapter()
        binding.rcvDetail.adapter = detailAdapter

    }

    override fun initData() {


        initListener()
    }

    private fun initListener() {
        binding.ivBack.setOnClickListener(this)

        binding.etSearch.setOnEditorActionListener(object : TextView.OnEditorActionListener {
            override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean {
                /*判断是否是“发送”键*/
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
//                    searchContent(et_input.getText().toString())
                    return true
                }
                return false
            }
        })
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view.id) {
            R.id.iv_back -> finish()
        }
    }
}